<%--
  Created by IntelliJ IDEA.
  User: 16549
  Date: 2022/1/16
  Time: 19:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/webjars/jquery/3.6.0/jquery.js"></script>
</head>
<body>
<form action="${pageContext.request.contextPath}/user/request4" method="post">
    <%-- 表明第一个User对象的name addr--%>
    <input type="text" name="userList[0].name" required/><br/>
    <input type="text" name="userList[0].addr" required/><br/>
    <input type="text" name="userList[1].name" required/><br/>
    <input type="text" name="userList[1].addr" required/><br/>
    <input type="submit" value="OK">
</form>
</body>
<script>
    $(document).ready(function () {
        var userList = new Array();
        userList.push({name: "大聪明", addr: "cs"})
        userList.push({name: "ylb", addr: "hy"})
        $.ajax({
            type: "post",
            data: JSON.stringify(userList),
            url: "${pageContext.request.contextPath}/user/ajax",
            contentType: "application/json;charset=utf-8",
            success: function () {
                $("body").append($("<h1>success</h1>"))
            }, error: function (xhr) {
                window.alert(xhr.status)
            }
        })

    })
</script>
</html>
